package com.bcx.service.impl;

import com.bcx.mapper.EntryMapper;
import com.bcx.pojo.Entry;
import com.bcx.pojo.EntryExample;
import com.bcx.service.EntryService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class EntryServiceImpl implements EntryService {
    @Resource
    EntryMapper entryMapper;
    @Override
    public PageInfo<Entry> selectAll(Integer categoryid, Integer pageNum) {
        PageHelper.startPage(pageNum,4);
        List<Entry> entryList;
        EntryExample entryExample=new EntryExample();
        if (categoryid!=0){
            EntryExample.Criteria criteria=entryExample.createCriteria();
            criteria.andCategoryidEqualTo(categoryid);
            entryList=entryMapper.selectByExample(entryExample);
        }else {
            entryList=entryMapper.selectByExample(null);
        }
        PageInfo<Entry> pageInfo=new PageInfo<>(entryList);
        return pageInfo;
    }

    @Override
    public Integer insert(Entry entry) {
        return entryMapper.insert(entry);
    }


    @Override
    public Integer delete(Integer id) {
    return entryMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Entry getById(Integer id) {
        return entryMapper.selectByPrimaryKey(id);
    }

    @Override
    public Integer update(Entry entry) {
        return entryMapper.updateByPrimaryKeySelective(entry);
    }


}
